package cn.edu.zafu.bigdata.XuShuXin.Exp1029;

import java.util.List;

/*作业1 ： 泛型*/

public class XsxMaxFinder {
    public static void main(String[] args) {
        List<Integer> intList = List.of(1, 88, 99, 66, 33, 152, 1523);
        Integer maxInt = findMax(intList);
        System.out.println("最大整数:" + maxInt);

        List<String> stringList = List.of("apple", "orange", "pear", "banana");
        String maxString = findMax(stringList);
        System.out.println("最大字符串：" + maxString);

    }

    public static <T extends Comparable<T>> T findMax(List<T> list){
        if (list == null || list.isEmpty()) {
            return null;
        }
        T max = list.get(0);
        for (T t : list) {
            if (t.compareTo(max) > 0) {
                max = t;
            }
        }
        return max;
    }

}
